﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Catering.DisplayBoards
{
    public partial class ClassDynamicBoard : System.Web.UI.Page
    {
        Catering_Rules.ClassInfo tClassInfo = new Catering_Rules.ClassInfo();//班组管理
        Catering_Rules.BanzuDynamic tBanzuDynamic = new Catering_Rules.BanzuDynamic();//班组动态管理

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.RepDataBind();
            }
        }

        /// <summary>
        /// 数据绑定
        /// </summary>
        public void RepDataBind()
        {
            DateTime SearchDateTime = DateTime.Now.AddDays(-1);
            if (Request.QueryString["Date"] != null)
            {
                SearchDateTime = Convert.ToDateTime(Request.QueryString["Date"]);
            }

            int AreaID = int.Parse(Request.QueryString["AreaID"].ToString()); //区域ID
            
            //获取对应班组集合
            List<Catering_Model.ClassInfo> ClassInfoList = tClassInfo.GetModelList("AreaID=" + AreaID);
            //获取所有班组对应的最后一次填写的数据
            //List<Catering_Model.BanzuDynamic> BanzuDynamicList = tBanzuDynamic.GetModelList("AreaID=" + AreaID, ClassInfoList.Count);

            //需绑定的数据源
            DataTable list = new DataTable();
            #region 添加表头
            list.Columns.Add("id");
            list.Columns.Add("KitchenNum");
            list.Columns.Add("KitchenArea");
            list.Columns.Add("qiyouzao");
            list.Columns.Add("diancizao");
            list.Columns.Add("penlin");
            list.Columns.Add("miehuoqi");
            list.Columns.Add("miehuotan");
            list.Columns.Add("shebeijiankong");
            list.Columns.Add("gaoweishebei");
            list.Columns.Add("shebeishuliang");
            list.Columns.Add("xiyishebei");
            list.Columns.Add("youyanji");
            list.Columns.Add("lengcangku");
            list.Columns.Add("dongku");
            list.Columns.Add("ganhuoku");
            list.Columns.Add("savedate");
            list.Columns.Add("ClassID");
            list.Columns.Add("zuoyerenshu");
            list.Columns.Add("zuoyeleixing");
            list.Columns.Add("zuoyezhouqi");
            list.Columns.Add("ClassName");
            #endregion
            foreach (Catering_Model.ClassInfo eClassInfo in ClassInfoList)
            {
                DataRow dr = list.NewRow();
                DataTable dt = new Catering_Rules.BanzuDynamic().GetList("ClassID =" + eClassInfo.id.ToString()).Tables[0];
                if(dt.Rows.Count>0)
                {
                    foreach (DataColumn dc in dt.Columns)
                    {
                        dr[dc.ColumnName] = dt.Rows[0][dc.ColumnName];
                    }
                    dr["ClassName"] = eClassInfo.CName;
                    list.Rows.Add(dr);
                }
            }

            this.Rep_List.DataSource = list;
            this.Rep_List.DataBind();

            ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, Page.GetType(), "script", "<script>$(function () { $(\".Table_2>tbody tr:odd\").addClass(\"Table_Tr_odd\"); });</script>", false);
        }

        //定时刷新页面
        protected void Btn_Ref_Click(object sender, EventArgs e)
        {
            this.RepDataBind();
        }
    }
}